<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Encrypt extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->library('encrypt');
	}

	public function index()
	{
		$this->load->view('encrypt');
	}
	
	public function encode()
	{
		if ($_POST) {
			$text = $this->input->post('text');
			$key = $this->input->post('key');
			if ($key) {
				$encrypted = $this->encrypt->encode($text, $key);
			} else {
				$encrypted = $this->encrypt->encode($text);
			}
			echo $encrypted;
			$this->load->view('encrypt');
		} else {
			echo 'error';
		}
	}
	
	public function decode()
	{
		if ($_POST) {
			$encrypted = $this->input->post('encrypted');
			$key = $this->input->post('key');
			if ($key) {
				$plaintext = $this->encrypt->decode($encrypted, $key);
			} else {
				$plaintext = $this->encrypt->decode($encrypted);
			}
			echo $plaintext;
			$this->load->view('encrypt');
		} else {
			echo 'error';
		}
	}
	
}

/* End of file Encrypt.php */
/* Location: ./application/controllers/Encrypt.php */